#include "myStack.h"

myStack::myStack(int capacity)
{
    m_size = 0;
    m_capacity = capacity;
    m_data = new char[m_capacity];
}

myStack::~myStack()
{
    delete [] m_data;
}
int myStack::reCacapity()
{
    char *tempData = m_data;
    int newCapacity = m_capacity << 1;
    m_data = new char[newCapacity];

    for(int idx = 0;idx < m_size;idx++)
    {
        m_data[idx]  = tempData[idx];
    }

    delete [] tempData;
    m_capacity = newCapacity;
    return 0;
}
void myStack::push(char data)
{   
    if(m_size >= m_capacity)
    {
        reCacapity();
    }
    this->m_data[m_size++] = data;
}
void myStack::pop()
{
    m_size--;
}
bool myStack::empty()
{
    return this->m_size == 0;
}
char myStack::top()
{
    return m_data[m_size-1];
}
int myStack::size()
{
    return m_size;
}
int myStack::capacity()
{
    return m_capacity;
}